//
//  KLReserveHotelViewController.m
//  KunLun
//
//  Created by Mac on 2017/11/28.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLReserveHotelViewController.h"

@interface KLReserveHotelViewController ()
@property(nonatomic, strong) NSArray<STTableEasyModel*>                     *dataSouce;
@property(nonatomic, strong) STLabel                     *moneyLable;
@end

@implementation KLReserveHotelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"预定酒店";
//    self.view.backgroundColor = KL_BlueBackGroundColor;
//    self.tableView.backgroundColor = KL_BlueBackGroundColor;
    [self configSubView];
    [self cofigDataSouce];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    headerView.backgroundColor = KL_BlueBackGroundColor;
    
    UIView * whiteview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, UIScreenWidth - 20, 180)];
    whiteview.backgroundColor = [UIColor whiteColor];
    whiteview.layer.cornerRadius = 5;
    whiteview.clipsToBounds = YES;
    [headerView addSubview:whiteview];
    //
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 10, whiteview.width - 20, 20)
                                                     text:@"的发掘开了房间时空裂缝"
                                                textColor:KL_firstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [whiteview addSubview:titleLable];
    
    STLabel * timeLable = [[STLabel alloc] initWithFrame:CGRectMake(10, titleLable.bottom + 3, whiteview.width - 20, 20)
                                                     text:@"2017年11月28日12:00:49 2017年11月28日12:00:55"
                                                textColor:KL_secendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [whiteview addSubview:timeLable];
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(10, timeLable.bottom + 3, whiteview.width - 20, 40)
                                                    text:@"的发掘dasdasdasdfsdfsdfsfdsdasdasd了房间时空裂缝"
                                               textColor:KL_secendTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    desLable.numberOfLines = 0;
    [whiteview addSubview:desLable];
    
    whiteview.height = desLable.bottom + 20;
    
    headerView.height = whiteview.bottom + 10;
    self.tableView.tableHeaderView = headerView;
    
    
    
    //底部
    UIView * bootomView = [[UIView alloc] initWithFrame:CGRectMake(0, UIScreenHeight - 50, UIScreenWidth, 50)];
    bootomView.backgroundColor = [UIColor whiteColor];
    [bootomView st_showTopShadow];
    self.moneyLable= [[STLabel alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth - 120, 50)
                                               text:@"在线支付:$220元"
                                                textColor:KL_redColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    self.moneyLable.attributedText = [self.moneyLable.text st_convertAttributeStringWithKeyWord:@"在线支付:" attributes:@{NSForegroundColorAttributeName:KL_firstTextColor}];
    [bootomView addSubview:self.moneyLable];
    __weak typeof(self) weakSelf =  self;
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(self.moneyLable.right, 0, 120, 50)
                                                     title:@"提交订单"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:15
                                              cornerRadius:0
                                           backgroundColor:KL_redColor
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [buyButton setClicAction:^(UIButton *sender) {
        [weakSelf onslectedBuyButton];
    }];
    [bootomView addSubview:buyButton];
    [self.view addSubview:bootomView];
}
- (void)cofigDataSouce{
    
    
    self.dataSouce = @[
                       [[STTableEasyModel alloc] initWithTextString:@"房间数" detailString:@""],
                         [[STTableEasyModel alloc] initWithTextString:@"手机" detailString:@""],
                         [[STTableEasyModel alloc] initWithTextString:@"预计到达" detailString:@"18.00前"]
                       ];
    [self.tableView reloadData];
}
- (UITextField*)defultTextfiledWithPlaceHodel:(NSString*)placeHolder keybordTYpe:(UIKeyboardType)keybordTYpe{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0.66 * UIScreenWidth, 44)];
    textFiled.backgroundColor = [UIColor whiteColor];
    textFiled.placeholder = placeHolder;
    textFiled.keyboardType= keybordTYpe;
    return textFiled;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce.count ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44  ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 60
    ;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * sectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 50)];
    sectionHeader.backgroundColor = KL_backgroundColor;
    STButton * numButton = [[STButton alloc] initWithFrame:CGRectMake(0, 10, UIScreenWidth, 40)
                                                     title:@"此房间只剩1件"
                                                titleColor:KL_firstTextColor
                                                 titleFont:15
                                              cornerRadius:0
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"火"]];
    numButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    numButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    [sectionHeader addSubview:numButton];
    return sectionHeader;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.textColor = UIColorFromRGBA(0x333333);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.textColor = UIColorFromRGBA(0x999999);
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    cell.textLabel.text = model.textString;
    cell.detailTextLabel.text = model.detailString;
    if (indexPath.row == 2) {
        cell.detailTextLabel.textColor = KL_BlueBackGroundColor;
    }else{
        cell.detailTextLabel.textColor = UIColorFromRGBA(0x999999);
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.row];
    if (indexPath.row != 2) {
        
        STTableViewDetailController * vc  =
        [[STTableViewDetailController alloc] initWithPlaceholder:[NSString stringWithFormat:@"请输入%@",model.textString]
                                                           title:model.textString
                                                        complete:^(NSString *text, STTableViewDetailController *detailControllerVC) {
                                                            
                                                            model.detailString = text;
                                                            [self.tableView reloadData];
                                                            [self.navigationController popViewControllerAnimated:YES];
                                                        }];
        vc.textFiled.keyboardType = UIKeyboardTypeNumberPad;
         vc.maxTextNum = 1000;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        //时间
        STPickerViewController * vc = [[STPickerViewController alloc] initWithPickerArray:@[[self timeArray],[self minteArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
            
            NSString  *finsh = [NSString stringWithFormat:@"%@:%@前",stringArray.firstObject,stringArray.lastObject];
            model.detailString = finsh;
            [self.tableView reloadData];
        }];
        [self presentViewController:vc animated:NO completion:nil];
        
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Private Method
- (NSArray*)timeArray{
    NSMutableArray * timeArray = [NSMutableArray new];
    for (int i = 8; i < 24; i ++ ) {
        NSString *hour = @(i).description;
        if (i < 10) {
            hour = [NSString stringWithFormat:@"0%@",hour];
        }
        [timeArray addObject:hour];
    }
    return timeArray;
}
- (NSArray*)minteArray{
    NSMutableArray * timeArray = [NSMutableArray new];
    for (int i = 0; i < 60; i ++ ) {
        NSString *min = @(i).description;
        if (i < 10) {
            min = [NSString stringWithFormat:@"0%@",min];
        }
        [timeArray addObject:min];
    }
    return timeArray;
}
#pragma mark --Action Method
- (void)onslectedBuyButton{
    
}
@end
